<?php
/**
 * Created by PhpStorm.
 * User: dengpan
 * Date: 2017/1/9
 * Time: 21:54
 */

$serv = new Swoole\Websocket\Server("127.0.0.1", 8002);

$serv->on('Open', function($server, $req) {
    echo "connection open: ".$req->fd . "\n";
});

$serv->on('Message', function($server, $frame) {
    echo "message: ".$frame->data;
    $data = "已接收: " . $frame->data . "    " . date("Y-m-d H:i:s");
    $server->push($frame->fd, $data);
});

$serv->on('Close', function($server, $fd) {
    echo "connection close: ".$fd;
});

$serv->start();